package com.sk.bilibili.model.fragment.search;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.FocusMapper;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.SearchMapper;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.search.ThemFragment;

public class ThemModel extends BaseSearchModel<ThemFragment>{

    @Autowired
    SearchMapper searchMapper;
    @Autowired
    FollowThemMapper followThemMapper;

    @Override
    protected JsonMap getJsonMap() {
        JsonMap map = super.getJsonMap();
        map.put("typeId",view.getTypeId());
        return map;
    }

    @Override
    public void loadData() {
        JsonMap map = getJsonMap();
        RequestUtils.process(searchMapper.searchThem(map), themPage -> {
            view.addData(themPage.getRecords());
            page++;
        });
    }

    @Override
    public void refreshData() {
        page=1;
        JsonMap map = getJsonMap();
        RequestUtils.process(searchMapper.searchThem(map), themPage -> {
            view.setData(themPage.getRecords());
            view.setNum(themPage.getTotal());
            page++;
        });
    }

    public void followThem(Integer id) {
        JsonMap map=new JsonMap();
        map.put("themId",id);
        RequestUtils.process(followThemMapper.add(map),
                unused -> view.followThemSuccess());
    }

}